<%--
 *  File:    ProtocolEditMain.jsp
 *  @Author: banshang
 *  Date:    2010/03/08
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  Category cat = Category.getInstance("jsp.ProtocolEditMain");
  String privilegeCode = "11201";
  String strModuleName = "PCM";
  String contextPath = request.getContextPath();
%>
<%
  String strIsNew=(String)request.getParameter("isnew");
  if(strIsNew==null)
    strIsNew="";
%>
<%
  HashMap userInfo = (HashMap)session.getAttribute("userinfo");

%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>

<html>
<head>
<title>ProtocolEditMain</title>
<PageFlow:CheckPageFlow pageName="p_protocoleditmain"/>
<%@ include file="/inc/InitEdit.inc" %>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<%@ include file="/inc/NewCalendar.inc" %>
<iframe name="reloadHandler" style="display:none" ></iframe>
<script language="JavaScript">
function setOrg(orgid,orgname){
	var flag = document.cform.flag.value;
	if(flag == 'first'){
		document.cform.secondorgid.value=orgid;
		document.cform.secondorgname.value=orgname;
	}else if(flag == 'second'){
		document.cform.thirdorgid.value=orgid;
		document.cform.thirdorgname.value = orgname;
	}
}
function page_save(){
	if(!checkForm(document.cform)) return;
	if(!formatDate(document.cform)) return;
	if(!checkStartEndDate()) return;
	if(!checkSecondThird()) return;
	
	document.cform.target = "_self"; 	
	document.cform.actionname.value = "save";
	document.cform.submit();
}

function checkSecondThird(){
	var secondorgid = document.cform.secondorgid.value;
	var thirdorgid = document.cform.thirdorgid.value;
	if(secondorgid == thirdorgid){
		alert("<%=message.getMessageDesc("VALUE_MUST_NOTEQUAL", label.getLabelName("L_SecondOrg"),label.getLabelName("L_ThirdOrg"))%>");
		return false;
	}
	return true;
}

function checkStartEndDate(){
	var startDate = toDate(document.cform.startdate.value);
	var endDate = toDate(document.cform.enddate.value);

	if(startDate>endDate){
		alert("<%=message.getMessageDesc("STARTDATE_CAN_NOT_LATE_THAN_ENDDATE", label.getLabelName("L_BeginDate"),label.getLabelName("L_EndDate"))%>");
		return false;
	}

	return true;
}

function page_back(){
	parent.location.href="ProtocolManagement.jsp?<%= OvalTools.randomURL() %>";
}

function changeProtocolType(){

	document.cform.salestarget.value='';
	document.cform.thirdorgid.value='';
	document.cform.thirdorgname.value='';
	
	var protocoltypeid = document.cform.protocoltypeid.value;
	
	var datahandler = new  DataHandler() ;
	
	datahandler.add_params("protocoltypeid" , protocoltypeid,"integer") ;
  	
  	datahandler.getResultFromHashMap("protocoltypeinfo" ,"agency" ,"document.cform.agency");
  	datahandler.getResultFromHashMap("protocoltypeinfo" ,"threepart" ,"document.cform.threepart");
  	datahandler.add_job("j_getprotocoltypeinfo") ;
  	datahandler.add_function("setDisplayFlag()");
  	
    datahandler.runDataHandler ();
}

function setDisplayFlag(){
	var agency = document.cform.agency.value;
	var threepart = document.cform.threepart.value;

	if(agency == 'Y'){
		document.getElementById('target').style.display='none';
		document.cform.salestarget.value='';
		document.cform.salestarget.command='';
	}else{
		document.getElementById('target').style.display='block';
		document.cform.salestarget.command='notnull,positive';
	}
	if(threepart == 'N'){
		document.getElementById('thirdorg').style.display='none';
		document.cform.thirdorgid.value='';
		document.cform.thirdorgid.command='';
	}else{
		document.getElementById('thirdorg').style.display='block';
		document.cform.thirdorgid.command='notnull';
	}
}

function page_submit(){
	var protocolid = document.cform.protocolid.value;	
	if(protocolid == '' || protocolid == null){
		alert("<%=message.getMessageDesc("SAVE_INFO_FIRST")%>");
		return;
	}

	if(!checkForm(document.cform)) return;
	if(!formatDate(document.cform)) return;
	if(!checkStartEndDate()) return;

	document.cform.target = "_parent"; 	
	document.cform.actionname.value = "submit";
	document.cform.submit();
}

function popProtocolArea(orgpart){
	var protocolid = document.cform.protocolid.value;
	if(protocolid == '' || protocolid == null){
		alert("<%=message.getMessageDesc("SAVE_INFO_FIRST")%>");
		return;
	}

	var property = 'height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no';

	var url = '<%=contextPath%>/template/CM/RelatedArea.jsp?orgpart='+orgpart+'&protocolmanageid='+protocolid;

	window.open (url, 'newwindow', property);	
}
function popOrgContact(orgpart){
	var protocolid = document.cform.protocolid.value;

	if(protocolid == null || protocolid == ''){
		alert("<%=message.getMessageDesc("SAVE_INFO_FIRST")%>");
		return;
	}
	
	var orgid = '';
	if(orgpart ==2){
		orgid = document.cform.secondorgid.value;
	}else{
		orgid = document.cform.thirdorgid.value;
	}
	var property = 'height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no';

	var url = '../ogm/HistoryOrgContact.jsp?orgpart='+orgpart+'&protocolid='+protocolid+'&orgid='+orgid;

	window.open (url, 'newwindow', property);	
}
</script>
</head>
<%
	HashMap protocolInfo = (HashMap)pageContext.getAttribute("protocolInfo");
	if(protocolInfo == null)
		protocolInfo = new HashMap();
	
	boolean disabled = false;
	
	Integer protocolid = (Integer)protocolInfo.get("protocolid");
	
	if(protocolid != null){
		disabled = true;
	}
	
	String threePart = (String)protocolInfo.get("threepart");
	String agency = (String)protocolInfo.get("agency");
	
	String targetDisplay = "";
	String thirdOrgDisplay = "";
	String targetCommand = "notnull,positive";
	String thirdOrgCommand = "notnull";
	if("N".equals(threePart)){
		thirdOrgDisplay = "display:none";
		thirdOrgCommand = "";
	}
	if("Y".equals(agency)){
		targetDisplay = "display:none";
		targetCommand = "";
	}
%>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr>
    <td valign=top>
      <table border=0 cellpadding=1 cellspacing=0 width="100%">
       <tbody>
       <form name="cform" method="post" action="<%=contextPath %>/Dispatcher">
      <input type="hidden" name="pagename" value="p_protocoleditmain">
      <input type="hidden" name="actionname">
      <custom:hidden name="protocolInfo" property="agency"/>
      <custom:hidden name="protocolInfo" property="threepart"/>      
	  <custom:hidden property="protocolid" name="protocolInfo"/>
	  <custom:hidden property="secondcustomertype" name="protocolInfo"/>
	  <custom:hidden property="thirdcustomertype" name="protocolInfo"/>
     
        <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                  <div id=div1 style="HEIGHT: 350px; OVERFLOW: auto">

        <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">

          
          <tr>
            <td colspan="4" class="deepblue-left"> <img src="<%=contextPath %>/images/<%= strLanguageCode %>/quote.gif">
              <%= label.getLabelName("L_BasicInfo") + label.getLabelName("L_Colon") %> </td>
          </tr>
          
          <tr>
            <td class="need" width="120"><%= label.getLabelName("L_ProtocolCode") + label.getLabelName("L_Colon") %></td>
            
            
            <td  >
             		<custom:text name="protocolInfo" property="protocolcode" command="notnull" label="L_ProtocolCode" ></custom:text>
            </td>
            <td class="need" width="106" ><%= label.getLabelName("L_ProtocolName") + label.getLabelName("L_Colon") %></td>
            <td >
			        <custom:text name="protocolInfo" property="protocolname" command="notnull" label="L_ProtocolName" />
            </td>
          </tr>
           
           <tr>
            <td class="need"  width="120"><%= label.getLabelName("L_AgreementType") + label.getLabelName("L_Colon") %></td>
            <td>
             	<%if(disabled){%>
					<custom:select name="protocolInfo" disabled="true" command="notnull" label="L_AgreementType" optionInnerTextKey="protocolname" optionsName="protocoltypes" property="protocoltypeid" optionValueKey="protocoltypeid" onchange="changeProtocolType()"/>
             		<custom:hidden name="protocolInfo" property="protocoltypeid"/>             		
             	<%}else{%>
             		<custom:select name="protocolInfo" command="notnull" label="L_AgreementType" defaultValue="--------------------------" optionInnerTextKey="protocolname" optionsName="protocoltypes" property="protocoltypeid" optionValueKey="protocoltypeid" onchange="changeProtocolType()"/>
             	<%}%>
            </td>
            <td class="need" width="106" ><%= label.getLabelName("L_FirstOrg") + label.getLabelName("L_Colon") %></td>
            <td >
            	<custom:hidden property="firstorgid" name="protocolInfo" label="L_FirstOrg" command="notnull" ></custom:hidden>
			    <custom:write name="protocolInfo" property="shortname"/>
            </td>
          </tr>

		  <tr>
            <td class="need"  width="120"><%= label.getLabelName("L_SecondOrg") + label.getLabelName("L_Colon") %></td>
            <td >
             	<custom:hidden property="secondorgid" name="protocolInfo" command="notnull" label="L_SecondOrg"></custom:hidden>
			    <custom:text name="protocolInfo" property="secondorgname" size="40" readonly="true" ></custom:text>
			    <a onclick="javascript:document.cform.flag.value='first';window.open ('../erm/OrgSummaryForPop.jsp?globalpccode='+document.cform.secondcustomertype.value, 'newwindow', 'height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');"><input type="button" class="button3" value="*"></a>	
            </td>
            <td class="td-text" width="106" ><%= label.getLabelName("L_SecondOrg") + label.getLabelName("L_SalesScope") + label.getLabelName("L_Colon") %></td>
            <td >
			    <a onclick="popProtocolArea(2)"><input type="button" class="button3" value="*"></a>
            </td>
          </tr>
          <tr id="thirdorg" style="<%= thirdOrgDisplay%>">
            <td class="need"  width="120"><%= label.getLabelName("L_ThirdOrg") + label.getLabelName("L_Colon") %></td>
            <td  >
             	<custom:hidden property="thirdorgid" name="protocolInfo" constant="<%=thirdOrgCommand %>" label="L_ThirdOrg"></custom:hidden>
			    <custom:text name="protocolInfo" property="thirdorgname" size="40" readonly="true" ></custom:text>
			    <a onclick="javascript:document.cform.flag.value='second';window.open ('../erm/OrgSummaryForPop.jsp?globalpccode='+document.cform.thirdcustomertype.value, 'newwindow', 'height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');"><input type="button" class="button3" value="*"></a>	
            </td>
            <td class="td-text" width="106" ><%= label.getLabelName("L_ThirdOrg") + label.getLabelName("L_SalesScope") + label.getLabelName("L_Colon") %></td>
            <td >
			    <a onclick="popProtocolArea(3)"><input type="button" class="button3" value="*"></a>
            </td>
          </tr>
          <custom:hidden property="flag"></custom:hidden>
          <tr>
            <td class="need" width="120"><%= label.getLabelName("L_BeginDate") + label.getLabelName("L_Colon") %></td>
            <td  >
             	<custom:text name="protocolInfo" property="startdate" label="L_BeginDate" command="notnull" dataType="date" dataFormatName="dateformat"></custom:text> 
             	<a onclick="javascript:c.show(this,'cform.startdate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');">
						<custom:button type="3" label="L_Asterisk"	imgsrc="../../images/cn/Time.gif" border="0" /> </a>
            </td>
            <td class="need" width="106" ><%= label.getLabelName("L_EndDate") + label.getLabelName("L_Colon") %></td>
            <td >
			     <custom:text name="protocolInfo" property="enddate" label="L_EndDate" command="notnull" dataType="date" dataFormatName="dateformat"></custom:text>
			     <a onclick="javascript:c.show(this,'cform.enddate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');">
						<custom:button type="3" label="L_Asterisk"	imgsrc="../../images/cn/Time.gif" border="0" /> </a>
            </td>
          </tr>
          
          <tr>
          	<td class="need" width="120" ><%= label.getLabelName("L_SignDate") + label.getLabelName("L_Colon") %></td>
            <td >
			     <custom:text name="protocolInfo" property="signdate" label="L_SignDate" command="notnull" dataType="date" dataFormatName="dateformat"></custom:text>
			     <a onclick="javascript:c.show(this,'cform.signdate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');">
						<custom:button type="3" label="L_Asterisk"	imgsrc="../../images/cn/Time.gif" border="0" /> </a>
            </td>
            
            <td class="td-text" width="106" ><%= label.getLabelName("L_ComMaker") + label.getLabelName("L_Colon") %></td>
            <td >
            	<custom:hidden property="maker" name="protocolInfo" ></custom:hidden>
			     <custom:write property="username" name="protocolInfo"/>
            </td>
          </tr>
          <tr>
            <td class="td-text" width="120"><%= label.getLabelName("L_CreateDate") + label.getLabelName("L_Colon") %></td>
            <td  >
             	 <custom:text name="protocolInfo" property="createdate" dataType="date" dataFormatName="dateformat" readonly="true" style="border:0px;"/>
            </td>
            
            <td class="td-text" width="106" ><%= label.getLabelName("L_Status") + label.getLabelName("L_Colon") %></td>
            <td >
			     <custom:write name="protocolInfo" property="status" dictType="Status" nbsp="true"/>
			     <custom:hidden name="protocolInfo" property="status"/>
            </td>
          </tr>
          
          <tr>
          	<td class="td-text" width="120"><%= label.getLabelName("L_Comments") + label.getLabelName("L_Colon") %></td>
            <td colspan="3">
            	<custom:text name="protocolInfo" property="comments" size="120" ></custom:text>
            </td>
          </tr>
          <tr id="target" style="<%=targetDisplay %>">
          	
            <td class="need" width="120"><%= label.getLabelName("L_SalesTargets") + label.getLabelName("L_Colon") %></td>
            <td colspan="3" >
             	<custom:text name="protocolInfo" property="salestarget" command="<%=targetCommand %>" label="L_SalesTargets"></custom:text>
            </td>
          </tr>
          
        </table>
       </div>
      </td>
    </tr>
   </table>
  </td>
 </tr>
  </form>
 </tbody>
</table>
</td>
</tr>
<tr>
  <td class="summary_top"></td>
</tr>
<tr>
  <td class="td_center">
  	<a onclick="page_submit();"><custom:button type="1" label="L_Submit" imgsrc="save_btn.gif" border="0" style="width:60"/></a>
  	<a onclick="page_save();"><custom:button type="1" label="L_Save" imgsrc="save_btn.gif" border="0" style="width:60"/></a>
   <a onclick="page_back()"><custom:button type="1" label="L_Back" imgsrc="back.gif" border="0" style="width:60"/></a>
  </td>
</tr>
</table>
<script>
</script>
</body>
</html>


